<html>
<head><meta charset="utf-8"><title>Lowering Index operator to MIR · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lowering.20Index.20operator.20to.20MIR.html">Lowering Index operator to MIR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230302458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lowering%20Index%20operator%20to%20MIR/near/230302458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lowering.20Index.20operator.20to.20MIR.html#230302458">(Mar 15 2021 at 07:01)</a>:</h4>
<p>I'm confused about this code: <a href="https://github.com/rust-lang/rust/blob/d6eaea1c8860adb5302d2fbaad409e36585ab217/compiler/rustc_mir_build/src/thir/cx/expr.rs#L329-L343">https://github.com/rust-lang/rust/blob/d6eaea1c8860adb5302d2fbaad409e36585ab217/compiler/rustc_mir_build/src/thir/cx/expr.rs#L329-L343</a> when is an index expression <code>x[a]</code> not lowered to a method call?</p>
<p>I tried adding an assert <code>assert!(self.typeck_results().is_method_call(expr));</code> right above that <code>if</code>, and it fails, at this expression: <code>line.as_bytes()[l - 1]</code> where line is a <code>&amp;str</code>.  I don't understand why this doesn't go through slice's <code>Index</code> impl.</p>



<a name="230310801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lowering%20Index%20operator%20to%20MIR/near/230310801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lowering.20Index.20operator.20to.20MIR.html#230310801">(Mar 15 2021 at 08:44)</a>:</h4>
<p><span class="user-mention" data-user-id="119169">@osa1</span> See <a href="https://internals.rust-lang.org/t/about-condition-in-which-hir-index-will-mirror-to-thir-index/13228">https://internals.rust-lang.org/t/about-condition-in-which-hir-index-will-mirror-to-thir-index/13228</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>